<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/9
 * Time: 11:35
 */
namespace app\admin\controller;
use think\Db;

class Index extends Base {

    /**
     * 后台首页
     */
    public function index(){
        $auth_info = Db::name('tbauth')->where('taobao_user_id',810608219)->find(); //获取授权信息
        $msg = "《-请点击授权";
        if(!empty($auth_info)){
            $msg = '过期时间：'.date('Y-m-d H:i:s',intval($auth_info['refresh_token_valid_time']/1000));
        }
        $oauth = "https://oauth.taobao.com/authorize?response_type=code&client_id=24741714&redirect_uri=https://mina.anymean.com/home/callback/tbauth&state=1212&view=web";

        $this->assign('msg',$msg);
        $this->assign('redirect_uri',$oauth);
        return $this->fetch();
    }

    /**
     * 欢迎首页
     */
    public function welcome(){
        $cate_list = Db::table('yf_items_cate')->field('id,name')->where(['parent_id'=>0])->select();
        foreach ($cate_list as $k=>$v){
            $num[] = Db::table('yf_items')->where(['fqcat'=>$v['id']])->count();
        }
        $this->assign('cate_list',$cate_list);
        $this->assign('num',$num);
        return $this->fetch();
    }

    /**
     * 空操作
     */
    public function _empty(){
        if($this->check_admin_login()){
            $this->redirect('admin/Index/index');
        }else{
            $this->redirect('admin/login');
        }
    }
}